package BehaviorModel.iterorModel;

import java.util.Iterator;

public class ComputerReserveIteror implements Iterator {

    private Department[] departments;

    private int index = 0;

    public ComputerReserveIteror(Department[] departments) {
        this.departments = departments;
        this.index=departments.length-1; // 重置又游标索引
    }

    public void setDepartments(Department[] departments) {
        this.departments = departments;
        this.index=departments.length-1;// 重置又游标索引
    }

    @Override
    public boolean hasNext() {
        if (index > 0) {
            return true;
        }
        return false;
    }

    @Override
    public Object next() {
        if (hasNext()){
            return departments[--index];
        }
        return null;
    }


    /***
     * 这里先采用空实现
     */
    @Override
    public void remove() {

    }
}
